﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public static class EmployerDB
    {
        public static List<WorkAds> GetWorkAdsByAccountId(int accountId)
        {
            var query =
                (from w in Model.GetContext().WorkAdsSets
                 where w.AccountId == accountId && w.Deleted == false
                 select w).ToList();

            //var query =
            //    Model.GetContext().WorkAdsSets.Where(w => 
            //        w.AccountId == accountId && w.Deleted == false).ToList();

            return query;
        }

        public static void DeleteWorkAd(int workId)
        {
            var query =
                (from w in Model.GetContext().WorkAdsSets
                    where w.WorkId == workId
                    select w).FirstOrDefault();

            query.Deleted = true;
            Model.GetContext().SaveChanges();
        }

        public static void AddWorkAd(WorkAds workAds)
        {
            Model.GetContext().WorkAdsSets.Add(workAds);
            Model.GetContext().SaveChanges();
        }
        public static void FillWorkAd(int workId)
        {
            var query =
                (from w in Model.GetContext().WorkAdsSets
                    where w.WorkId == workId
                    select w).FirstOrDefault();

            var lQuery = Model.GetContext().WorkAdsSets
                .FirstOrDefault(w => w.WorkId == workId);

            query.Filled = true;
            query.Deleted = true;
            Model.GetContext().SaveChanges();
        }
    }
}
